package collection.generic;

import java.util.LinkedList;
import java.util.Queue;

public class Tree<T> {
	Node<T> root;
	
	public Tree(Node<T> root) {
		this.root = root;
	}
	
	public boolean exist(T value) {
		Queue<Node<T>> queue = new LinkedList<>();
		queue.add(root);
		
		while (!queue.isEmpty()) {
			Node<T> node = queue.poll();
			if (node.value == value) return true;
			
			for (Node<T> child : node.children) {
				queue.add(child);
			}
		}
		return false;
	}
}
